export const findKeyPath = (
  target: string,
  arr: Recordable[],
  field = 'key',
  currentPath: string[] = [],
): string[] | null => {
  for (const item of arr) {
    // 当前路径
    const newPath = [...currentPath, item[field]];

    // 找到目标 key，返回完整路径
    if (item[field] === target) {
      return newPath;
    }

    // 有子节点，继续递归查找
    if (item.children && item.children.length > 0) {
      const result = findKeyPath(target, item.children, field, newPath);
      if (result) return result;
    }
  }

  // 未找到路径
  return null;
};
